// Copyright (c) 2011 The Kiwii Authors. All rights reserved.
// Use of this source code is governed by the New BSD License that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#ifndef KIWII_CLIENT_INCLUDED
#define KIWII_CLIENT_INCLUDED

#include "net/EventLoopBase.hxx"
#include "net/TcpConnection.hxx"
#include <unistd.h>
#include <string>

namespace kiwii {

  //forward declaration
  namespace comm {
    namespace protocol {
      class Request;
      class Reply;
    }
  }

  class KClient {
  public:
    KClient(int fd, net::EventLoopBase& el);
    virtual ~KClient() {}

    int id() const { return conn_.fd(); }
    
    virtual void onRequest(comm::protocol::Request const& req) = 0;

  protected:
    void sendReply(std::string const& reply) {
      conn_.send(reply.data(), reply.size());
    }

  private:
    net::TcpConnection conn_;
  };

}

#endif
